import useGlobalAPI from '@/hooks/useGlobalAPI'
import {
  conf_modules_state,
  getRoleTreeDatas,
  getTreeDatas,
  MainViewContent,
  MainViewContentNav,
  MainViewModel,
} from './components'

export default defineComponent({
  name: 'conf-modules',
  setup() {
    let {route, router} = useGlobalAPI()
    let {currentRole} = toRefs(conf_modules_state)
    onMounted(async () => {
      if (route.query.roleCode && route.query.roleName) {
        currentRole.value.roleCode = (route.query.roleCode as RoleCode) || null
        currentRole.value.roleName = (route.query.roleName as RoleName) || null
        getTreeDatas()
        getRoleTreeDatas()
      } else {
        router.push('/conf/role')
      }
    })
    return () => (
      <div class="h-full bg-default">
        <MainViewContentNav></MainViewContentNav>
        <MainViewContent></MainViewContent>
        <MainViewModel></MainViewModel>
      </div>
    )
  },
})
